#include "PhysicsComponentsUpdater.h"
#include "../Physics/ParticleComponent.h"

using namespace Pantsu;

PhysicsComponentsUpdater::PhysicsComponentsUpdater() 
	:
	m_v3GravityForce( 0.0f, -10.1f, 0.0f ),
	m_fGroundHeightness( 0.0f )
{
}

PhysicsComponentsUpdater::~PhysicsComponentsUpdater() {
}

void PhysicsComponentsUpdater::UpdateComponents( float i_deltaTime ) {

	std::list<Component*>::iterator itr = m_Components.begin();

	for ( itr; itr != m_Components.end(); ++itr ) {
		/* Compute the Collision */
		
		if ( static_cast<ParticleComponent*>(*itr)->GetVelocity().X > 0.001f ) {
			if ( static_cast<ParticleComponent*>(*itr)->GetPosition().Y < m_fGroundHeightness ) {
				//static_cast<ParticleComponent*>(*itr)->AddForce(Vector3(0.0f, 10.0f, 0.0f));
				Vector3 newVel = static_cast<ParticleComponent*>(*itr)->GetVelocity() * -0.9f;
				newVel.X *= -0.9f;
				static_cast<ParticleComponent*>(*itr)->SetVelocity(newVel);
			}

			static_cast<ParticleComponent*>(*itr)->SetAcceleration( m_v3GravityForce );	
			(*itr)->Update( i_deltaTime );
		}
	}
}

void PhysicsComponentsUpdater::UpdateForces( float i_deltaTime ) {
}

void PhysicsComponentsUpdater::UpdateIntegration( float i_deltaTime ) {
}

void PhysicsComponentsUpdater::ComputeCollision( const ParticleComponent *obj1, const ParticleComponent *obj2 )
{

}